#include<stdio.h>

bool Function1(char ch[])
{
	int num_P=0,num_T=0,num_A=0;
	for(int i=0;ch[i]!='\0';i++){
		if(ch[i]=="P")	num_P++;
		else if(ch[i]=="T") num_T++;
		else if(ch[i]=="A") num_A++;
		else return false;
		if(!(num_P && num_T && num_A)) return false;
		else return true;
	}
}

bool Function2(char ch[])
{

}

bool Function3(char ch[])
{

}

int main()
{
	int n;
	scanf("%d", &n);

	char ch[1000];

	//进行n组条件判断
	for(int i=0;i<n;i++)
	{
		bool judge_1,judge_2,judge_3;
		scanf("%s",ch[]);
		
		//条件1:必须只包含PAT
		judge_1 = Function1(ch[1000]);
		
		//条件2:
		judge_2 = Function2(ch[1000]);

		//条件3:
		judge_3 = Function3(ch[1000]);

		if(judge_1 && judge_2 && judge_3) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

